<div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
    <p class="pull-left" style="font-size:16px; line-height:30px;"><strong><?php echo $this->translate('优惠券'); ?></strong></p>
    <p class="pull-right">
        <a href="<?php echo $this->url('coupon/default',array('action'=>'add')); ?>" class="btn btn-small btn-primary"><i class="icon-plus icon-white"></i> <?php echo $this->translate('添加优惠券'); ?></a>&nbsp;
        <a href="<?php echo $this->myviewalias()->dbshopHelpUrl('goods_coupon_set'); ?>" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
    </p>
</div>
<table class="table table-hover">
    <thead style="background:#CCC;">
    <tr>
        <th width="15%"><?php echo $this->translate('优惠券名称'); ?></th>
        <th width="20%"><?php echo $this->translate('优惠券描述'); ?></th>
        <th width="15%"><?php echo $this->translate('有效时间'); ?></th>
        <th width="6%"><?php echo $this->translate('已发放数'); ?></th>
        <th width="6%"><?php echo $this->translate('未使用数'); ?></th>
        <th width="6%"><?php echo $this->translate('已使用数'); ?></th>
        <th width="6%"><?php echo $this->translate('已过期数'); ?></th>
        <th width="8%"><?php echo $this->translate('状态'); ?></th>
        <th width="8%"><?php echo $this->translate('获取方式'); ?></th>
        <th width="10%"><?php echo $this->translate('操作'); ?></th>
    </tr>
    </thead>
    <?php
    if ($this->coupon_list) {
        foreach ($this->coupon_list as $rule_val) {
            ?>
            <tr>
                <td><?php echo $this->escapeHtml($rule_val['coupon_name']); ?></td>
                <td><?php echo $rule_val['coupon_info']; ?></td>
                <td><?php
                    $start_time = empty($rule_val['coupon_start_time']) ? '' : date("Y-m-d H:i", $rule_val['coupon_start_time']);
                    $end_time   = empty($rule_val['coupon_end_time']) ? '' : date("Y-m-d H:i", $rule_val['coupon_end_time']);
                    if($start_time == '' and $end_time == '') {
                        $start_and_end_time = $this->translate('长期有效');
                    } elseif ($end_time != '' and time() > $rule_val['coupon_end_time']) {
                        $start_and_end_time = '<font color="#FF0000">' . $this->translate('已经过期') . '</font>';
                    } else {
                        $start_and_end_time = (empty($start_time) ? $this->translate('无') : $start_time) . ' / ' . (empty($end_time) ? $this->translate('无') : $end_time);
                    }

                    echo $start_and_end_time; ?>
                </td>
                <td>
                    <?php if($rule_val['ca_num'] > 0) { ?>
                        <a href="<?php echo $this->url('coupon/default',array('action'=>'userCoupon','id'=>$rule_val['coupon_id'])); ?>"><?php echo $rule_val['ca_num']; ?></a>
                    <?php } else { ?>
                    0
                    <?php } ?>
                </td>
                <td>
                    <?php if($rule_val['cn_num'] > 0) { ?>
                        <a href="<?php echo $this->url('coupon/default',array('action'=>'userCoupon','id'=>$rule_val['coupon_id'])); ?>"><?php echo $rule_val['cn_num']; ?></a>
                    <?php } else { ?>
                        0
                    <?php } ?>
                </td>
                <td>
                    <?php if($rule_val['cy_num'] > 0) { ?>
                        <a href="<?php echo $this->url('coupon/default',array('action'=>'userCoupon','id'=>$rule_val['coupon_id'])); ?>"><?php echo $rule_val['cy_num']; ?></a>
                    <?php } else { ?>
                        0
                    <?php } ?>
                </td>
                <td>
                    <?php if($rule_val['ce_num'] > 0) { ?>
                        <a href="<?php echo $this->url('coupon/default',array('action'=>'userCoupon','id'=>$rule_val['coupon_id'])); ?>"><?php echo $rule_val['ce_num']; ?></a>
                    <?php } else { ?>
                        0
                    <?php } ?>
                </td>
                <td><?php echo $rule_val['coupon_state'] == 1 ? $this->translate('开启') :$this->translate('关闭'); ?></td>
                <td>
                    <?php
                    $getTypeArray = array('click'=>$this->translate('点击获取'), 'register'=>$this->translate('注册获取'), 'buy'=>$this->translate('下单(购买)获取'));
                    echo $getTypeArray[$rule_val['get_coupon_type']];
                    ?>
                </td>
                <td style="vertical-align:middle">
                    <a href="<?php echo $this->url('coupon/default',array('action'=>'edit','id'=>$rule_val['coupon_id'])); ?>"><?php echo $this->translate('编辑'); ?></a>
                    <span>|</span>
                    <a href="javascript:;" onclick="coupon_del_js(<?php echo $rule_val['coupon_id']; ?>);"><?php echo $this->translate('删除'); ?></a>
                </td>
            </tr>
            <?php
        }
    } else {
        ?>
        <tr><td colspan="5"><?php echo $this->translate('暂无优惠券信息'); ?></td></tr>
    <?php } ?>
</table>
<script>
    //优惠券删除操作js
    function coupon_del_js(coupon_id) {
        if(window.confirm('<?php echo $this->translate('您确实要删除该优惠券吗？'); ?>')) {
            $.post("<?php echo $this->url('coupon/default',array('action'=>'del', 'id'=>$rule_val['coupon_id'])); ?>",{coupon_id:coupon_id},
                function(data){
                    if(data == 'true') {
                        window.location.reload();
                    } else {
                        alert(data);
                    }
                });
        }
    }
</script>